home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume5 / mapmem < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  18.7 KB

  1. Path: xanth!ames!mailrus!tut.cis.ohio-state.edu!cwjcc!hal!ncoast!allbery
  2. From: mjy@sdti.sdti.com (Michael J. Young)
  3. Newsgroups: comp.sources.misc
  4. Subject: v05i066: Program to Display Memory Allocation in System V
  5. Message-ID: <341@sdti.SDTI.COM>
  6. Date: 3 Dec 88 00:36:04 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: mjy@sdti.sdti.com (Michael J. Young)
  9. Organization: Software Development Technologies, Sudbury MA
  10. Lines: 722
  11. Approved: allbery@ncoast.UUCP
  12.  
  13. Posting-number: Volume 5, Issue 66
  14. Submitted-by: "Michael J. Young" <mjy@sdti.sdti.com>
  15. Archive-name: mapmem
  16.  
  17. Mapmem displays a visual map of physical memory and swap device allocation
  18. for System V Unix.  The map is updated at 1 second intervals, providing a
  19. real-time view of system memory utilization.
  20.  
  21. I'm sure there are lots of utilities out there that do things like this,
  22. but I don't have them here.  I hope someone else finds it useful as well.
  23.  
  24. Please send bug reports/fixes, etc., to me.
  25.  
  26.  
  27. #! /bin/sh
  28. # This is a shell archive.  Remove anything before this line, then unpack
  29. # it by saving it into a file and typing "sh file".  To overwrite existing
  30. # files, type "sh file -c".  You can also feed this as standard input via
  31. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  32. # will see the following message at the end:
  33. #        "End of archive 1 (of 1)."
  34. # Contents:  Makefile README mapmem.8 mapmem.c
  35. # Wrapped by mjy@sdti on Wed Nov 30 16:04:20 1988
  36. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  37. if test -f Makefile -a "${1}" != "-c" ; then 
  38.   echo shar: Will not over-write existing file \"Makefile\"
  39. else
  40. echo shar: Extracting \"Makefile\" \(733 characters\)
  41. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  42. X## @(#)$Id: Makefile, V1.1.1.3 88/11/30 16:03:44 $
  43. X##
  44. X## MAPMEM makefile
  45. X## Version  : 1.1.1.3 - 88/11/30 16:03:44
  46. X##
  47. X
  48. X## edit as appropriate...
  49. XCFLAGS = -g -O
  50. XLDFLAGS =
  51. XLIBFLAGS = -lcurses
  52. X
  53. X## Directory in which executable should be placed:
  54. XDESTDIR = /usr/local/bin
  55. X
  56. X## Directory in which man page should be placed:
  57. XMANDIR = /usr/man/l_man/man8
  58. X
  59. X## MAPMEM must have read access to /dev/kmem.  Therefore, it must be
  60. X## setgid to some group with the appropriate privilege.
  61. XGRPID = sys
  62. X
  63. Xmapmem : mapmem.c
  64. X    $(CC) $(LDFLAGS) $(CFLAGS) -o mapmem mapmem.c $(LIBFLAGS)
  65. X
  66. Xinstall: mapmem
  67. X    cp mapmem $(DESTDIR)/mapmem
  68. X    chgrp $(GRPID) $(DESTDIR)/mapmem
  69. X    chmod g+s $(DESTDIR)/mapmem
  70. X    cp mapmem.8 $(MANDIR)/mapmem.8
  71. X    chmod 444 $(MANDIR)/mapmem.8
  72. END_OF_Makefile
  73. if test 733 -ne `wc -c <Makefile`; then
  74.     echo shar: \"Makefile\" unpacked with wrong size!
  75. fi
  76. # end of overwriting check
  77. fi
  78. if test -f README -a "${1}" != "-c" ; then 
  79.   echo shar: Will not over-write existing file \"README\"
  80. else
  81. echo shar: Extracting \"README\" \(501 characters\)
  82. sed "s/^X//" >README <<'END_OF_README'
  83. XMAPMEM displays a visual map of physical memory and swap device allocations
  84. Xfor a swapping (i.e., non-paged) Unix system.  The map is updated at 1 second
  85. Xintervals, providing a real-time indication of system memory utilization.
  86. X
  87. XTo install, simply edit the makefile and type 'make'.  Typing 'make install'
  88. Xwill install the executable with the appropriate privileges.
  89. X
  90. XMAPMEM requires read access to /dev/kmem, and must therefore be run as
  91. Xsetgid to some group with the appropriate access (e.g., sys).
  92. END_OF_README
  93. if test 501 -ne `wc -c <README`; then
  94.     echo shar: \"README\" unpacked with wrong size!
  95. fi
  96. # end of overwriting check
  97. fi
  98. if test -f mapmem.8 -a "${1}" != "-c" ; then 
  99.   echo shar: Will not over-write existing file \"mapmem.8\"
  100. else
  101. echo shar: Extracting \"mapmem.8\" \(943 characters\)
  102. sed "s/^X//" >mapmem.8 <<'END_OF_mapmem.8'
  103. X.\" @(#)$ mapmem.8, Version 1.1.1.1 - 88/11/28 18:16:51
  104. X.TH MAPMEM 8
  105. X.ad b
  106. X.SH NAME
  107. Xmapmem \- display map of core and swap allocation.
  108. X.SH SYNOPSIS
  109. X.B mapmem
  110. X[
  111. X.B \-d #
  112. X] [
  113. X.B \-vh?
  114. X]
  115. X.SH DESCRIPTION
  116. X.I Mapmem
  117. Xdisplays a visual map of physical memory and swap device
  118. Xallocation of a swapping (i.e., non-paged) Unix system.  The map display is
  119. Xupdated at periodic intervals, providing a real-time indication of system
  120. Xmemory utilization.
  121. X.I Mapmem
  122. Xuses
  123. X.I curses(3x)
  124. Xfor its screen output, based on the \fBTERM\fR environment variable.
  125. X.SH OPTIONS
  126. X.IP \fB-d#\fR
  127. XDelay '\fB#\fR' seconds between updates.  Defaults to 1 second.
  128. X.IP \fB-h\fR
  129. XDisplay a short usage message.
  130. X.IP \fB-v\fR
  131. XDisplay version and patch level of
  132. X.I mapmem .
  133. X.IP \fB-?\fR
  134. XSame as \fB-h\fR.
  135. X.SH BUGS
  136. XProbably.
  137. X.SH "SEE ALSO"
  138. X.I curses(3x) ,
  139. X.I terminfo(4)
  140. X.SH AUTHOR
  141. XMichael J. Young
  142. X.br
  143. Xharvard!sdti!mjy
  144. X.br
  145. XInternet : mjy@sdti.SDTI.COM
  146. X.SH VERSION
  147. X1.1 - 88/11/28 18:16:51
  148. END_OF_mapmem.8
  149. if test 943 -ne `wc -c <mapmem.8`; then
  150.     echo shar: \"mapmem.8\" unpacked with wrong size!
  151. fi
  152. # end of overwriting check
  153. fi
  154. if test -f mapmem.c -a "${1}" != "-c" ; then 
  155.   echo shar: Will not over-write existing file \"mapmem.c\"
  156. else
  157. echo shar: Extracting \"mapmem.c\" \(12856 characters\)
  158. sed "s/^X//" >mapmem.c <<'END_OF_mapmem.c'
  159. Xstatic char sccsid[] = "@(#)$Id: mapmem.c, V1.1.1.2 88/11/28 18:16:45 $";
  160. X
  161. X/*
  162. X * map.c - display kernel allocation map information
  163. X * Version : 1.1.1.2 - 88/11/28 18:16:45
  164. X * Author   : Michael J. Young
  165. X * USmail   : Software Development Technologies, Inc.
  166. X *            375 Dutton Rd
  167. X *            Sudbury MA 01776
  168. X * UUCP     : harvard!sdti!mjy
  169. X * Internet : mjy@sdti.SDTI.COM
  170. X *
  171. X * =========================================================================
  172. X * Copyright (C) 1988, Michael J. Young.
  173. X * Permission is hereby granted to copy and distribute this program for
  174. X * non-commercial purposes, provided that this notice is not removed.
  175. X *
  176. X * This program is being provided "as is", with no warrantee as to safety or
  177. X * accuracy of results.
  178. X *
  179. X * Please send bug reports and enhancements to me at the above address.
  180. X * =========================================================================
  181. X */
  182. X
  183. X/*
  184. X * Modification History:
  185. X *
  186. X * Wed Nov 23 09:39:01 EST 1988 - M. Young (mjy@sdti.SDTI.COM),
  187. X *    Originated.
  188. X */
  189. X
  190. X#define patch_level 0
  191. X
  192. X#include <nlist.h>
  193. X#include <stdio.h>
  194. X#include <sys/map.h>
  195. X#include <sys/param.h>
  196. X#include <fcntl.h>
  197. X#include <curses.h>
  198. X#include <sys/types.h>
  199. X#include <time.h>
  200. X#include <varargs.h>
  201. X#include <signal.h>
  202. X
  203. X/*
  204. X * sizes of the two major allocation maps maintained by the kernel.  These
  205. X * values are actually contained in the linkkit config.h.  If that file is
  206. X * not available, they must be set here.
  207. X */
  208. X#ifdef    SMAPSIZ
  209. X# define SMAPSIZE    SMAPSIZ
  210. X#else
  211. X# define SMAPSIZE  75
  212. X#endif
  213. X
  214. X#ifdef    CMAPSIZ
  215. X# define CMAPSIZE    CMAPSIZ
  216. X#else
  217. X# define    CMAPSIZE 150
  218. X#endif
  219. X
  220. X/*
  221. X * The following definitions specify the dimensions of the display map.
  222. X * Change to suit your tastes.
  223. X */
  224. X#define    MAX_ROWS    20
  225. X#define    MAX_COLUMNS    64
  226. X#define MAX_ENTRIES    (MAX_ROWS*MAX_COLUMNS)
  227. X
  228. X/*
  229. X * the following defines are used to index the namelist array.  Their
  230. X * definitions must be consistent with the order of the namelist array.
  231. X */
  232. X#define CORE_MAP    0
  233. X#define    SWAP_MAP     1
  234. X#define MAX_MEM     2
  235. X#define    N_SWAP         3
  236. X#define    PHYS_MEM    4
  237. X
  238. X/*
  239. X * namelist array : contains a list of names to be extracted from the kernel
  240. X * image using the nlist function.
  241. X */
  242. Xstruct nlist namelist[] = {
  243. X    { "coremap", 0, 0, 0, 0, 0 },
  244. X    { "swapmap", 0, 0, 0, 0, 0 },
  245. X    { "maxmem",  0, 0, 0, 0, 0 },
  246. X    { "nswap",   0, 0, 0, 0, 0 },
  247. X    { "physmem", 0, 0, 0, 0, 0 },
  248. X    { "",        0, 0, 0, 0, 0 }
  249. X};
  250. X
  251. Xstruct map smapbf[SMAPSIZE];        /* local copy of swap allocation map */
  252. Xstruct map cmapbf[CMAPSIZE];        /* local copy of core allocation map */
  253. Xint kmaxmem = 0;            /* local copy of maxmem */
  254. Xint kphysmem = 0;            /* local copy of physmem */
  255. Xint knswap = 0;                /* local copy of nswap */
  256. X
  257. Xint kmem = 0;                /* file handle for kernel memory */
  258. Xint delay = 1;                /* seconds between screen updates */
  259. X
  260. Xchar dmap[MAX_ENTRIES] = 0;        /* display map */
  261. X
  262. Xint swap_scale = 1;            /* scale factor for swap map display */
  263. Xint core_scale = 1;            /* scale factor for core map display */
  264. X
  265. X/*
  266. X * various useful definitions
  267. X */
  268. Xtypedef int boolean;
  269. X
  270. X/*#define    FALSE    0        /* defined in curses.h */
  271. X/*#define    TRUE    1        /* defined in curses.h */
  272. X
  273. X/*
  274. X * various function declarations
  275. X */
  276. Xextern long lseek();
  277. Xextern int read();
  278. Xextern time_t time();
  279. X
  280. X/*
  281. X * interface to system error messages
  282. X */
  283. Xchar *prog_name = NULL;
  284. X
  285. Xextern char *sys_errlist[];
  286. Xextern int sys_nerr;
  287. Xextern int errno;
  288. X
  289. X/*
  290. X * error : performs a function similar to perror(3), but supports variable
  291. X * argument lists.  Prints out a formatted error string to stderr, followed if
  292. X * possible by an appropriate system error message.  Control is then
  293. X * returned to the system with an error status.  This function does not
  294. X * return.
  295. X */
  296. X/* VARARGS0 */
  297. Xvoid error (va_alist)
  298. Xva_dcl                            /* varargs */
  299. X{
  300. X    int err;                      /* 1st arg - error number */
  301. X    char *str;                    /* 2nd arg - error format string */
  302. X    va_list args;
  303. X    va_start(args);
  304. X    err = va_arg (args, int);
  305. X    str = va_arg (args, char *);
  306. X    fprintf (stderr, "%s: ", prog_name);
  307. X    vfprintf (stderr, str, args);
  308. X    if (err != 0){
  309. X    if (err <= sys_nerr && err > 0)
  310. X            fprintf (stderr, " : %s\n", sys_errlist[err]);
  311. X        else
  312. X            fprintf (stderr, " : unknown error : %d\n", err);
  313. X    }
  314. X    va_end(args);
  315. X    endwin();
  316. X    exit(1);
  317. X}
  318. X
  319. Xvoid version (){
  320. X    printf ("\nKernel Allocation Map Display\n");
  321. X    printf ("Version : 1.1 - 88/11/28 18:16:45, Patch Level %d\n", patch_level);
  322. X}
  323. X
  324. Xvoid usage(){
  325. X    version();
  326. X    printf ("Usage : map [-[?h]] [-d#]\n\n");
  327. X    printf ("\t-d#\tDelay '#' seconds between screen updates.  Defaults\n");
  328. X    printf ("\t\tto 1 second.\n");
  329. X    printf ("\t-h\tDisplays this message.\n");
  330. X    printf ("\t-v\tDisplays version and patch level of program.\n");
  331. X    printf ("\t-?\tDisplays this message.\n");
  332. X}
  333. X
  334. X/*
  335. X * get_nlist : fetches the required namelist from the kernel image
  336. X */
  337. Xvoid get_nlist(){
  338. X    if (nlist ("/unix", namelist) != 0){
  339. X        error (errno, "could not get namelist");
  340. X    }
  341. X}
  342. X
  343. X/*
  344. X * open_kmem : opens kernel memory
  345. X */
  346. Xvoid open_kmem(){
  347. X
  348. X    /*
  349. X     * open kernel memory
  350. X     */
  351. X    if ((kmem=open ("/dev/kmem", O_RDONLY)) == -1){
  352. X        error (errno, "could not open /dev/kmem");
  353. X    }
  354. X}
  355. X
  356. X/*
  357. X * init_kmem : reads kernel memory to initialize various static values
  358. X * that are important for future processing.
  359. X */
  360. Xvoid init_kmem (){
  361. X    /*
  362. X     * fetch maxmem (maximum free memory available to a process)
  363. X     */
  364. X    if (lseek (kmem, namelist[MAX_MEM].n_value, 0) != namelist[MAX_MEM].n_value){
  365. X        error (errno, "could not seek maxmem");
  366. X    }
  367. X    if (read (kmem, &kmaxmem, sizeof (int)) != sizeof (int)){
  368. X        error (errno, "could not read maxmem");
  369. X    }
  370. X
  371. X    /*
  372. X     * fetch physmem (maximum physical memory present in the system)
  373. X     */
  374. X    if (lseek (kmem, namelist[PHYS_MEM].n_value, 0) != namelist[PHYS_MEM].n_value){
  375. X        error (errno, "could not seek physmem");
  376. X    }
  377. X    if (read (kmem, &kphysmem, sizeof (int)) != sizeof (int)){
  378. X        error (errno, "could not read physmem");
  379. X    }
  380. X
  381. X    /*
  382. X     * fetch nswap (total blocks in the swap device)
  383. X     */
  384. X    if (lseek (kmem, namelist[N_SWAP].n_value, 0) != namelist[N_SWAP].n_value){
  385. X        error (errno, "could not seek nswap");
  386. X    }
  387. X    if (read (kmem, &knswap, sizeof (int)) != sizeof (int)){
  388. X        error (errno, "could not read nswap");
  389. X    }
  390. X
  391. X    /*
  392. X     * calculate the scale factor for the display maps.  The scale
  393. X     * factors should be set in such a way that a single screen can
  394. X     * display the entire map.  The scale factors are then massaged to
  395. X     * ensure that they are always even.  This is done in multiple
  396. X     * statements to ensure that smart compilers don't optimize the
  397. X     * multiplies and divides away.  I'm sure there's a more elegant
  398. X     * and reliable way, but this seems to work.
  399. X     */
  400. X    swap_scale = (knswap + MAX_ENTRIES - 1) / MAX_ENTRIES;
  401. X    swap_scale = (swap_scale + 1) / 2;
  402. X    swap_scale *= 2;
  403. X    core_scale = (kphysmem + MAX_ENTRIES - 1) / MAX_ENTRIES;
  404. X    core_scale = (core_scale + 1) / 2;
  405. X    core_scale *= 2;
  406. X}
  407. X
  408. X/*
  409. X * read_map : copies the specified kernel allocation map into local memory
  410. X * for future processing.
  411. X */
  412. Xvoid read_map(loc, buf, size)
  413. Xdaddr_t loc;                /* location in kernel to be read */
  414. Xstruct map *buf;            /* buffer in which to place copy */
  415. Xunsigned size;                /* number of map entries to read */
  416. X{
  417. X    if (lseek (kmem, loc, 0) != loc){
  418. X        error (errno, "could not seek kernel map");
  419. X    }
  420. X    if (read (kmem, buf, size*sizeof (struct map)) != size*sizeof (struct map)){
  421. X        error (errno, "could not read kernel map");
  422. X    }
  423. X}
  424. X
  425. X/*
  426. X * update_map : modifies all of the appropriate display map cells according
  427. X * that are affected by the specified kernel allocation map item.
  428. X */
  429. Xvoid update_map (dmap, mp, scale)
  430. Xchar dmap[];
  431. Xstruct map *mp;
  432. Xint scale;
  433. X{
  434. X    int entry;
  435. X    int map_index;
  436. X    int size;
  437. X    size = mp->m_size;
  438. X    for (entry = mp->m_addr; size; entry++){
  439. X         map_index = entry / scale;
  440. X        dmap[map_index] = 0;
  441. X        size--;
  442. X    }
  443. X}
  444. X
  445. X/*
  446. X * interpret_map : scans through the copy of the kernel allocation map and
  447. X * updates the specified display map accordingly.  The total number of free
  448. X * blocks in the map are returned.
  449. X */
  450. Xint interpret_map(dmap, kmp, scale)
  451. Xchar dmap[];
  452. Xstruct map *kmp;
  453. Xint scale;
  454. X{
  455. X    int total_free = 0;
  456. X    struct map *mp;
  457. X    memset (dmap, 1, MAX_ENTRIES);
  458. X    for (mp = kmp; mp->m_size; mp++){
  459. X        total_free += mp->m_size;
  460. X        update_map (dmap, mp, scale);
  461. X    }
  462. X    return total_free;
  463. X}
  464. X
  465. X/*
  466. X * print_map : scans the allocation map, displaying it in the standard
  467. X * window.  Allocated cells are marked with an asterisk ('*'), and free
  468. X * cells are marked with a period ('.').
  469. X */
  470. Xvoid print_map(dmap, scale, total_size)
  471. Xchar dmap[];
  472. Xint scale;
  473. Xlong total_size;
  474. X{
  475. X    int i, j, k;
  476. X    int entry;
  477. X    move (2,0);
  478. X    for (i = 0; i < MAX_ROWS; i++){
  479. X        k = i*MAX_COLUMNS;
  480. X        if (((long)k*scale) >= total_size)break;
  481. X        printw ("%08lx:  ", (long)k * scale);
  482. X        for (j = 0; j < MAX_COLUMNS; j++){
  483. X            if ((((long)k+j)*scale) >= total_size)break;
  484. X            entry = (i*MAX_COLUMNS+j);
  485. X            if (dmap[entry] != 0)addch ('*');
  486. X            else addch ('.');
  487. X        }
  488. X        addch ('\n');
  489. X    }
  490. X}
  491. X
  492. Xvoid interrupt (sig)
  493. Xint sig;
  494. X{
  495. X    move (0,0);
  496. X    clrtobot();
  497. X    refresh();
  498. X    endwin();
  499. X    exit(0);
  500. X}
  501. X
  502. X/*
  503. X * init : performs system and curses initialization
  504. X */
  505. Xvoid init (argc, argv)
  506. Xint argc;
  507. Xchar *argv[];
  508. X{
  509. X    int i;
  510. X    boolean done;
  511. X    char *cp;
  512. X
  513. X    /*
  514. X     * before we go any further, disable interrupts
  515. X     */
  516. X    signal (SIGINT, SIG_IGN);
  517. X    signal (SIGQUIT, SIG_IGN);
  518. X    signal (SIGHUP, SIG_IGN);
  519. X    signal (SIGTERM, SIG_IGN);
  520. X
  521. X    /*
  522. X     * save program name for future reference
  523. X     */
  524. X    prog_name = argv[0];
  525. X
  526. X    for (i = 1; i < argc; i++){
  527. X        cp = argv[i];
  528. X        if (*cp == '-'){
  529. X            done = FALSE;
  530. X            while (*++cp && !done){
  531. X                switch (*cp){
  532. X
  533. X                case 'd':    /* delay */
  534. X                    if (cp[1]){
  535. X                        delay = atoi (++cp);
  536. X                        done = TRUE;
  537. X                    }
  538. X                    else {
  539. X                        delay = atoi (argv[++i]);
  540. X                    }
  541. X                    break;
  542. X
  543. X                case 'v':    /* display version */
  544. X                    version();
  545. X                    exit(0);
  546. X
  547. X                case '?':    /* usage */
  548. X                case 'h':
  549. X                    usage();
  550. X                    exit(0);
  551. X
  552. X                default:
  553. X                    fprintf (stderr, "illegal option : %c; ignored.\n", *cp);
  554. X                    break;
  555. X                }
  556. X            }
  557. X        }
  558. X    }
  559. X
  560. X    /*
  561. X     * curses initialization
  562. X     */
  563. X    initscr();
  564. X    cbreak();
  565. X    noecho();
  566. X    nodelay (stdscr, 1);
  567. X
  568. X    /*
  569. X     * print out a simple command menu
  570. X     */
  571. X    mvaddch (23, 0, '[');
  572. X    attrset (A_BOLD);
  573. X    addch ('m');
  574. X    attroff (A_BOLD);
  575. X    addch (',');
  576. X    attrset (A_BOLD);
  577. X    addch ('c');
  578. X    attroff (A_BOLD);
  579. X    addstr ("]=memory allocation map   [");
  580. X    attrset (A_BOLD);
  581. X    addch ('s');
  582. X    attroff (A_BOLD);
  583. X    addstr ("]=swap allocation map    [");
  584. X    attrset (A_BOLD);
  585. X    addch ('q');
  586. X    attroff (A_BOLD);
  587. X    addch (',');
  588. X    attrset (A_BOLD);
  589. X    addch ('x');
  590. X    attroff (A_BOLD);
  591. X    addch (',');
  592. X    attrset (A_BOLD);
  593. X    addch ('e');
  594. X    attrset (A_NORMAL);
  595. X    addstr ("]=exit");
  596. X
  597. X    /*
  598. X     * now that curses is initialized, catch the interrupt signal
  599. X     * so we can die gracefully
  600. X     */
  601. X    signal (SIGINT, interrupt);
  602. X    signal (SIGQUIT, interrupt);
  603. X    signal (SIGHUP, interrupt);
  604. X    signal (SIGTERM, interrupt);
  605. X
  606. X    /*
  607. X     * get ready to access kernel memory
  608. X     */
  609. X    open_kmem();
  610. X    get_nlist ();
  611. X    init_kmem();
  612. X}
  613. X
  614. Xint main (argc, argv)
  615. Xint argc;
  616. Xchar *argv[];
  617. X{
  618. X    struct tm *tmbuf;        /* to hold current time */
  619. X    time_t tm;
  620. X    boolean done = FALSE;        /* will be nonzero when ready to quit */
  621. X    int mem_or_swap = 0;        /* 0 = display core map, 1 = swap map */
  622. X    int free = 0;            /* free items in allocation map */
  623. X
  624. X    init (argc, argv);
  625. X    while (!done){
  626. X
  627. X        /*
  628. X         * get and display current time
  629. X         */
  630. X        time (&tm);
  631. X        tmbuf = localtime (&tm);
  632. X        move (0,0);
  633. X        clrtoeol();
  634. X        mvprintw (0, 67, "%02d:%02d:%02d", tmbuf->tm_hour, tmbuf->tm_min, tmbuf->tm_sec);
  635. X
  636. X        if (mem_or_swap == 0){
  637. X
  638. X            /*
  639. X             * update and display core map
  640. X             */
  641. X            read_map (namelist[CORE_MAP].n_value, cmapbf, CMAPSIZE);
  642. X            free = interpret_map (dmap, cmapbf, core_scale);
  643. X            standout();
  644. X            mvaddstr (0, 31, "Memory Allocation");
  645. X            standend();
  646. X            move (1,0);
  647. X            clrtoeol();
  648. X            mvprintw (1,  0, "Total Memory = %ld KBytes, %ld Kernel, %ld Free",
  649. X                ((long)kphysmem*NBPC)/1024,
  650. X                ((long)(kphysmem-kmaxmem)*NBPC)/1024, 
  651. X                ((long)free*NBPC)/1024);
  652. X            mvprintw (1, 58, "Scale Factor = %2d", core_scale);
  653. X            print_map (dmap, core_scale*NBPC, (long)kphysmem*NBPC);
  654. X        }
  655. X        else {
  656. X
  657. X            /*
  658. X             * update and display swap map
  659. X             */
  660. X            read_map (namelist[SWAP_MAP].n_value, smapbf, SMAPSIZE);
  661. X            free = interpret_map (dmap, smapbf, swap_scale);
  662. X            standout();
  663. X            mvaddstr (0, 29, "Swap Device Allocation");
  664. X            standend();
  665. X            move (1,0);
  666. X            clrtoeol();
  667. X            mvprintw (1,  0, "Total swap space = %d Blocks, %d Free", knswap, free);
  668. X            mvprintw (1, 58, "Scale Factor = % d", swap_scale);
  669. X            print_map (dmap, swap_scale, (long)knswap);
  670. X        }
  671. X
  672. X        /*
  673. X         * refresh the screen and wait a while
  674. X         */
  675. X        refresh();
  676. X        sleep (delay);
  677. X
  678. X        /*
  679. X         * look for any new commands
  680. X         */
  681. X        switch (getch()){
  682. X        case 'c':    /* switch to core (memory) map */
  683. X        case 'm':
  684. X            mem_or_swap = 0;
  685. X            break;
  686. X
  687. X        case 's':    /* switch to swap map */
  688. X            mem_or_swap = 1;
  689. X            break;
  690. X
  691. X        case 'q':    /* quit */
  692. X        case 'e':
  693. X        case 'x':
  694. X            done = TRUE;
  695. X            break;
  696. X
  697. X        default:    /* illegal command, ignore it */
  698. X            break;
  699. X        }
  700. X            
  701. X    }
  702. X    move (0,0);
  703. X    clrtobot();
  704. X    refresh();
  705. X    endwin();
  706. X}
  707. X
  708. END_OF_mapmem.c
  709. if test 12856 -ne `wc -c <mapmem.c`; then
  710.     echo shar: \"mapmem.c\" unpacked with wrong size!
  711. fi
  712. # end of overwriting check
  713. fi
  714. echo shar: End of archive 1 \(of 1\).
  715. cp /dev/null ark1isdone
  716. MISSING=""
  717. for I in 1 ; do
  718.     if test ! -f ark${I}isdone ; then
  719.     MISSING="${MISSING} ${I}"
  720.     fi
  721. done
  722. if test "${MISSING}" = "" ; then
  723.     echo You have unpacked all 1 archives.
  724.     rm -f ark[1-9]isdone
  725. else
  726.     echo You still need to unpack the following archives:
  727.     echo "        " ${MISSING}
  728. fi
  729. ##  End of shell archive.
  730. exit 0
  731. -- 
  732. Mike Young
  733. Software Development Technologies, Inc., Sudbury MA       Tel: +1 508 443 5779
  734. Internet: mjy@sdti.sdti.com                 UUCP: {harvard,mit-eddie}!sdti!mjy
  735.